package com.realtyManage.springboot.Config;

import com.realtyManage.springboot.Model.Do.CustomerRegistration;
import com.realtyManage.springboot.Service.IApplyInfoService;
import com.realtyManage.springboot.Service.ICustomerRegistrationService;
import com.realtyManage.springboot.Service.ICustomerService;
import com.realtyManage.springboot.Service.ISpecialOfferHouseService;
import com.realtyManage.springboot.Service.impl.UserTaskServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

/**
 * SaticScheduleTask
 *
 * 报备超时，每天凌晨2点自动检查
 * 带访超时，每天凌晨3点自动检查
 *
 * @Author 杭州素色网络科技有限公司
 * @Date 2019/7/6
 * 定时器
 **/

@Component
@Configuration
@EnableScheduling
public class SaticScheduleTask {
    @Autowired
    private IApplyInfoService applyInfoService;

    @Autowired
    private ICustomerRegistrationService customerRegistrationService;

    @Autowired
    private UserTaskServiceImpl userTaskService;

    //定时增加来访人员，每天凌晨0点
    @Scheduled(cron = "0 0 0 */1 * ?")
    private void addCustomerTimeTasks() {
        System.err.println("增加来访人员-开始时间: " + LocalDateTime.now());
        customerRegistrationService.addCustomer();
        System.err.println("增加来访人员-结束时间: " + LocalDateTime.now());
    }

    //定时检测客户跟踪信息
    @Scheduled(cron = "0 0 0 */1 * ?")
    private void updateCustomerTimeTasks() {
        System.err.println("检测来访人员跟踪时间-开始时间: " + LocalDateTime.now());
       // userTaskService.updateCustomerTimeTasks();
        System.err.println("检测来访人员跟踪时间-结束时间: " + LocalDateTime.now());
    }

    /***
     * 30分钟执行查看报备过期
     */
    @Scheduled(cron = "0 */30 * * * ?")
    private void updateZfTasks() {
        System.err.println("报备过期扫描: " + LocalDateTime.now());
        applyInfoService.scanGq();
    }

    //每隔8小时扫描注册用户到公池中
   // @Scheduled(cron = "0 0 */8 * * ?")
    @Scheduled(cron = "0 */10 * * * ?")
    private void updateInternetPublicUser() {
        System.err.println("进入公池-开始时间: " + LocalDateTime.now());
        userTaskService.updateInternetPublicUser();
        System.err.println("进入公池-结束时间: " + LocalDateTime.now());
    }


    //每隔1小时扫描客户列表中的非全号客户信息删除
    @Scheduled(cron = "0 0 */1 * * ?")
    private void deleteFCustomer() {
        System.err.println("查询非全号-开始时间: " + LocalDateTime.now());
        userTaskService.deleteFCustomer();
        System.err.println("查询非全号-结束时间: " + LocalDateTime.now());
    }
}
